/*
 * @Date: 2022-03-21 09:49:52
 * @LastEditors: zhaoxm
 * @LastEditTime: 2022-08-31 18:37:53
 * @Description: message 提示框 ， 避免重复点击 出现多个提示
 */

import element from "element-ui"
import Vue from "vue"
const { Message } = element

const app = new Vue()

export const showMessage = (text, type = "success") => {
  Message.closeAll()
  Message[type](text)
}

export const closeMessage = () => {
  Message.closeAll()
}

export const removeMessage = () => {
  for (const element_ of document.querySelectorAll(".el-message")) element_.remove()
}

export const showMessageBox = (content, title, callback) => {
  const config = {
    confirmButtonText: "确定",
    callback,
  }

  if (typeof callback === "object") {
    Object.assign(config, callback)
  } else {
    config.callback = callback
  }

  app.$alert(title, content, config)
}
